server_out=server.out
cgi_out=cgi.out
out_all=$(server_out) $(cgi_out)
main=main.cc
http_dir=./http
wwwroot=./wwwroot
cgi_dir=./cgi
cgi_file_list=$(cgi_dir)/cgi.cc
cgi_out=cgi.out
reactor_dir=./tcp_reactor
reactor_filelist=$(main) $(reactor_dir)/epoller.hh $(reactor_dir)/tcp_reactor.hh $(reactor_dir)/socket.hh $(reactor_dir)/connection.hh
release_dir=./release
debug_dir=./debug
standerd=-std=c++11
all:$(out_all)
cgi.out: $(cgi_file_list)
	g++ $^ -o $(cgi_dir)/$@ $(standerd) -O3
	cp $(cgi_dir)/$@ $(wwwroot)
server.out: $(reactor_filelist)
	g++ $(main) $(standerd) -lpthread -o $@ -O3
.PHONY:clean
clean:
	rm -rf $(out_all) $(release_dir) $(debug_dir)
.PHONY:debug
debug:
	rm -rf $(out_all) $(debug_dir)
	g++ $(cgi_file_list) -o $(cgi_out) $(standerd) -O3 -D DEBUG
	g++ $(main) $(standerd) -lpthread -o $(server_out) -O3 -D DEBUG
	mkdir debug
	ln  ../wwwroot debug/wwwroot -s
	mv $(cgi_out) $(debug_dir)/wwwroot/$(cgi_out)
	mv $(server_out) debug/$(server_out)		
.PHONY:release
release: 
	make clean
	make
	mkdir release
	ln -s ../wwwroot release/
	mv server.out release/		
